package com.chwl.framework.grpc.junit;

import com.chwl.framework.grpc.GrpcClientService;
import com.chwl.framework.grpc.etcd.EtcdService;
import com.chwl.framework.grpc.exception.UserdefinedException;

/**
 * <p>功能:</p>
 *
 * @date:2018-07-15 下午5:49<br/>
 * @version:1.0 <br/>
 */
public class GrpcClientServiceJunit {

    public static void main(String[] args) throws UserdefinedException {

        EtcdService.getInstance().connection("http://119.23.225.123:6500");
        new Thread(() -> {
            try {
                Thread.sleep(Integer.MAX_VALUE);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        new Thread(() -> {
            while (true) {
                try {
                    Object object = GrpcClientService.getInstance().invoke("accountService", "findAll");
                    System.out.println("accountService.findAll:" + object);
                    Object addResult = GrpcClientService.getInstance().invoke("accountService", "add", 1);
                    System.out.println("accountService.add:" + addResult);
                    if (object != null) {
                        return;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        Thread.sleep(5000);
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            }
        }).start();
    }
}
